/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package action;

import dao.CustomerDAO;
import dao.mysql.CustomerDAOImpl;
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import model.Customer;
import model.Transaksi;
import utility.DBConnection;

/**
 *
 * @author Student
 */
public class InvoiceCreateAction implements Action {

    @Override
    public String execute(HttpServletRequest request) {
        String url = "";
        HttpSession sesi = request.getSession(true);
        DBConnection db = new DBConnection();
        CustomerDAO dao = new CustomerDAOImpl(db.getConnection());
        try {
            Customer cust = dao.getById(Integer.valueOf(request.getParameter("customer")));
            Transaksi transaksi = new Transaksi();
            transaksi.setCustomer(cust);
            transaksi.setTgl(new Date());
            
            sesi.setAttribute("invoice", transaksi);
          
            url = "invoice_new_2.jsp";
        } catch (Exception ex) {
            request.setAttribute("message", ex.getMessage());
            url = "controller?action=invoice_new";
        }
        return url;
    }
}
